import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class TestEncoding {
    public static void main(String[] args) {
        try {
            // 测试数据库连接和字符编码
            String url = "jdbc:mysql://127.0.0.1:3306/carbon_db?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true&autoReconnect=true&useLocalSessionState=true&connectionCollation=utf8mb4_unicode_ci&useServerPrepStmts=true&rewriteBatchedStatements=true&useCompression=true&characterSetResults=utf8mb4";
            String username = "root";
            String password = "root123456";
            
            Connection conn = DriverManager.getConnection(url, username, password);
            Statement stmt = conn.createStatement();
            
            // 设置字符集
            stmt.execute("SET NAMES utf8mb4");
            
            // 查询菜单数据
            ResultSet rs = stmt.executeQuery("SELECT id, menu_name FROM sys_menu WHERE id <= 5 ORDER BY id");
            
            System.out.println("数据库查询结果:");
            while (rs.next()) {
                System.out.println("ID: " + rs.getLong("id") + ", 菜单名称: " + rs.getString("menu_name"));
            }
            
            rs.close();
            stmt.close();
            conn.close();
            
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
